//
//  MVClassifyDetailCollectionViewCell.m
//  NewMusic
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "MVClassifyDetailCollectionViewCell.h"

@interface MVClassifyDetailCollectionViewCell ()
@property(nonatomic, retain) UIImageView *picUrlImageView;
@property(nonatomic, retain) UILabel *videoNameLabel;
@property(nonatomic, retain) UILabel *singerNameLabel;
@property(nonatomic, retain) UIImageView *showImageView;
@property(nonatomic, retain) UILabel *showLabel;
@property(nonatomic, retain) UIView *backView;
@property(nonatomic, retain) UIView *smallView;
@end


@implementation MVClassifyDetailCollectionViewCell
- (void)dealloc {
    [_picUrlImageView release];
    [_videoNameLabel release];
    [_singerNameLabel release];
    [_showImageView release];
    [_showLabel release];
    [_newMVModel release];
    [_backView release];
    [_smallView release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //创建视图
        [self createSubView];
    }
    return self;
}
- (void)createSubView {
    //背景图片
    self.backView = [[UIView alloc]init];
    _backView.backgroundColor = [UIColor whiteColor];
    _backView.alpha = 0.05;
    [self.contentView addSubview:_backView];
    [_backView release];
   //图片
    self.picUrlImageView = [[UIImageView alloc]init];
//    _picUrlImageView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_picUrlImageView];
    [_picUrlImageView release];
    
    //MV名字
    self.videoNameLabel = [[UILabel alloc]init];
//    _videoNameLabel.backgroundColor = [UIColor purpleColor];
    _videoNameLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_videoNameLabel];
    [_videoNameLabel release];
    
    //歌手名字
    self.singerNameLabel = [[UILabel alloc]init];
//    _singerNameLabel.backgroundColor = [UIColor cyanColor];
    _singerNameLabel.textColor = [UIColor grayColor];
    _singerNameLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_singerNameLabel];
    [_singerNameLabel release];
    
    self.smallView = [[UIView alloc]init];
    _smallView.backgroundColor = [UIColor blackColor];
    _smallView.alpha = 0.2;
    [self.contentView addSubview:_smallView];
    [_smallView release];
    
    //播放图片
    self.showImageView = [[UIImageView alloc]init];
//    _showImageView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_showImageView];
    [_showImageView release];
    //播放人数
    self.showLabel = [[UILabel alloc]init];
//    _showLabel.backgroundColor = [UIColor greenColor];
    _showLabel.textColor = [UIColor whiteColor];
    _showLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:_showLabel];
    [_showLabel release];
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    //背景
    _backView.frame = CGRectMake(0, 0, self.width, self.height);
    //图片
    _picUrlImageView.frame = CGRectMake(0, 0, self.width, self.height / 3 * 2);
    //名字
    _videoNameLabel.frame = CGRectMake(0, _picUrlImageView.bottomY, _picUrlImageView.width, self.height / 6);
    //歌手名字
    _singerNameLabel.frame = CGRectMake(0, _videoNameLabel.bottomY, _videoNameLabel.width, _videoNameLabel.height);
    _showImageView.frame = CGRectMake(_picUrlImageView.width - 60, 5, 15, 15);
    _showLabel.frame = CGRectMake(_showImageView.rightX + 4, _showImageView.y, 40, _showImageView.height);
    _smallView.frame = CGRectMake(_showImageView.x, _showImageView.y, 59, _showImageView.height);
    
}
- (void)setNewMVModel:(TheNewMVModel *)newMVModel {
    if (_newMVModel != newMVModel) {
        [_newMVModel release];
        _newMVModel = [newMVModel retain];
    }
    //图片
    [_picUrlImageView sd_setImageWithURL:[NSURL URLWithString:newMVModel.picUrl]];
    //名字
    _videoNameLabel.text = newMVModel.videoName;
    //歌手名字
    _singerNameLabel.text = newMVModel.singerName;
    //播放的图片
    _showImageView.image = [UIImage imageNamed:@"icon_luyinji2"];
    if (newMVModel.pickCount.length < 5 && ![newMVModel.pickCount isEqualToString:@"0"]) {
        _showLabel.text = newMVModel.pickCount;
    }else if (newMVModel.pickCount.length >= 5){
    _showLabel.text = [NSString stringWithFormat:@"%@万", [NSNumber numberWithFloat:[[NSString stringWithFormat:@"%.1f", [newMVModel.pickCount floatValue] / 10000 ] floatValue]]];
    }else if ([newMVModel.pickCount isEqualToString:@"0"]) {
        _showImageView.frame = CGRectMake(_picUrlImageView.width - 25, 5, 15, 15);
        _showLabel.frame = CGRectMake(0, 0, 0, 0);
        _smallView.frame = CGRectMake(_showImageView.x, _showImageView.y, 15, _showImageView.height);
    }
    }
@end
